package com.tarena.lbs.user.service.impl;

import com.tarena.lbs.user.dao.repository.AdminRepository;
import com.tarena.lbs.user.pojo.param.AdminLoginParam;
import com.tarena.lbs.user.pojo.po.AdminPO;
import com.tarena.lbs.user.pojo.vo.AdminVO;

import com.tarena.lbs.user.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class AdminLongServiceImpl implements AdminService {
    @Autowired
    private AdminRepository adminRepository;

//    @Override
//    public Result<LoginVO> select(AdminLoginParam param) {
//        log.debug("商家登录业务层参数{}" , param);
//        if (!(param.getPhone()== null || param.getPassword() == null)) {
//           Result<LoginVO> list = adminRepository.select(param);
//           return list;
//        }else {
//            return Result.fail();
//        }
//
//    }

    @Override
    public AdminVO login(AdminLoginParam param) {
        AdminPO adminPO = adminRepository.login(param);
        if (adminPO == null) {
           throw new RuntimeException();
        }
        if (!param.getPassword().equals(adminPO.getAccountPassword())){
            throw new RuntimeException();
        }
        AdminVO adminVO = new AdminVO();
        BeanUtils.copyProperties(adminPO, adminVO);


        return adminVO;
    }

    @Override
    public AdminVO detail(Integer id) {
        AdminPO adminPO =  adminRepository.detail(id);
        AdminVO adminVO = new AdminVO();
        BeanUtils.copyProperties(adminPO, adminVO);
        return adminVO;
    }
}
